<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="<?php echo __PUBLIC__?>/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="<?php echo __PUBLIC__?>/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link rel="shortcut icon" href="<?php echo __PUBLIC__?>/Admin/Flat/img/favicon.ico">
	    <script type="text/javascript" src="Public/uploadify/jquery-1.8.2.min.js"></script>
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	</head>
	<body>
		<style type="text/css">
			.index{
				background: grey;
				color: #ffffff;
				margin-right: 5px;
			}
		</style>
		<script type="text/javascript">
			$(function(){
				$.each($('.status'), function(k, v) {
					if($(this).text()=='已完成'){
						$(this).parents('tr').find('.queren').html('<a class="btn btn-sm index">已签收</a>')
					}
					if($(this).text()=='未付款'){
						$(this).parents('tr').find('.queren').html('<a class="btn btn-sm index">等待付款</a>')
					}
					if($(this).text()=='已发货'){
						$(this).parents('tr').find('.queren').html('<a class="btn btn-sm index">待签收</a><a href="javascript:;" class="btn btn-sm btn-danger">撤销</a>')
					}
				});
				
				// 确认发货
				$('.btn-warning').live('click', function() {
					var _this = $(this);
					var oid = $(this).parents('tr').find('.oid').text();
					// 发送ajax
					$.ajax({
						url: '<?php echo U('ajaxQr')?>',
						type: 'POST',
						dataType: 'json',
						data: {oid: oid},
						success:function(data){
							if(data.status){
								_this.parents('tr').find('.status').html('已发货');
								_this.parents('tr').find('.queren').html('<a class="btn btn-sm index">待签收</a><a href="javascript:;" class="btn btn-sm btn-danger">撤销</a>');
							}
						}
					})
				});

				// 撤销方法
				$('.btn-danger').live('click', function() {
					var _this = $(this);
					var oid = $(this).parents('tr').find('.oid').text();
					// 发送ajax
					$.ajax({
						url: '<?php echo U('ajaxCx')?>',
						type: 'POST',
						dataType: 'json',
						data: {oid: oid},
						success:function(data){
							if(data.status){
								_this.parents('tr').find('.status').html('待发货');
								_this.parents('tr').find('.queren').html('<a href="javascript:;" class="btn btn-sm btn-warning">确认发货</a>');
							}
						}
					})
				});
			})
		</script>
		<table class="table table-hover">
			<tr class="active">
			  <th width="30">oid</th>
			  <th width="200">订单号</th>
			  <th width="100">价格</th>
			  <th width="150">订单状态</th>
			  <th>生成时间</th>
			  <th width="200">操作</th>
			</tr>
			<?php foreach ($orders as $k=>$v){?>
			<tr>
				<td class="oid"><?php echo $v['oid']?></td>
				<td><?php echo $v['onumber']?></td>
				<td><?php echo $v['total']?></td>
				<td class="status"><?php echo $v['status']?></td>
				<td><?php echo date('Y-m-d H:i:s',$v['time'])?></td>
				<td class="queren">
					<a href="javascript:;" class="btn btn-sm btn-warning">确认发货</a>
				</td>
			</tr>
			<?php }?>
		</table>
	</body>
</html>
